<template>
  <div class="login">
    <div class="wrapper">
      <!-- 头部 star -->
      <div class="header">
        <div class="head">
          <div class="header_left">
            <router-link to="/my" tag="a"
              ><img :src="require('../assets/img/su_back.webp')" alt=""
            /></router-link>
          </div>
          <div class="header_center">
            <p>登录</p>
          </div>
          <div class="header_right"></div>
        </div>
        <div class="launcher">
          <img :src="require('../assets/img/ic_launcher.png')" alt="" />
        </div>
      </div>
      <!-- 头部 end -->

      <!-- 账号登录 star  -->
      <div class="login">
        <div class="phone">
          <input type="text" placeholder="请输入手机号" v-model="phone"/>
        </div>
        <div class="password">
          <input type="passwoed" placeholder="请输入密码" v-model="password"/>
        </div>
        <div class="VerificationCode">
          <input type="text" placeholder="请输入验证码" v-model="code"/>
          <button class="btn" @click="getCode">获取验证码</button>
        </div>
      </div>
      <!-- 账号登录 end  -->

      <!-- 登录协议  star -->
      <div class="agreement">
        <div :class="['check',{'con':flag}]" @click="check"></div>
        <p>
          我已阅读并同意<span>《用户协议》</span>和<span>《隐私政策》</span>
        </p>
      </div>
      <!-- 登录协议  end -->

      <!-- 立即登录 star  -->
      <div class="go">
        <div class="register" @click="submit">立即登录</div>
      </div>
      <!-- 立即登录 end  -->
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      phone: "",
      password: "",
      code: "",
      flag:false,
      go:null,
    }
  },
  methods: {
    // 获取验证码
    getCode() {
      // 1.验证手机号码
      let reg =
        /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
      if (!reg.test(this.phone)) {
        //不正确处理
        this.$toast("验证码发送失败,手机号码错误");
        return;
      }else{
        this.$toast("验证码发送成功");
      }
    },
    submit(){
        // 验证手机号码与密码

      // 1.验证手机号码
      let reg =
        /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
      // 2.验证密码
      let pass = /^[a-zA-Z0-9]\w{8,17}$/;
      // 3.验证码
      // let code = /^[0-9]{4}$/;
    //   if (!reg.test(this.phone) || !pass.test(this.password)) {
    //     //不正确处理
    //     this.$toast("请输入正确手机号码与密码");
    //     return;
    //   }

     if(reg.test(this.phone) && pass.test(this.password)){
         window.localStorage.setItem("token", this.phone);
            window.localStorage.setItem("userId", this.password);
            if(this.flag==true){
                this.$toast("登陆成功");
                this.$router.push("/my");
            }else{
                this.$toast("请同意并选中用户协议以及隐私政策");
            }
     }else{
        this.$toast("请输入正确手机号码与密码");
     }
    },
    check(){
        this.flag=!this.flag
    }
  },
  created(){
    this.go = this.$route.query.go;
  }
};
</script>

<style lang="scss" scoped>
.login {
  .wrapper {
    min-width: 320px;
    max-width: 750px;
    margin: 0 auto;
  }
  .header {
    height: 230px;
    background: url(../assets/img/iv_login_bg.png) 0 no-repeat;
    width: 100%;
    background-size: 100% 230px;
    position: relative;
    .launcher {
      position: absolute;
      left: 50%;
      bottom: 0px;
      transform: translateX(-50%) translateY(50%);
      img {
        height: 89px;
        width: 89px;
        display: block;
      }
    }
  }
  .head {
    height: 50px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    padding: 0 28px 0 16px;
  }
  .header_left {
    img {
      height: 23px;
      display: block;
    }
  }

  .login {
    margin-top: 96px;
    display: flex;
    flex-direction: column;
    align-items: center;
    & > div {
      position: relative;
      input {
        outline: none;
        height: 40px;
        width: 300px;
        margin: 5px 0;
        font-size: 14px;
        border: none;
        border-bottom: 1px solid #999;
      }
      .btn {
        position: absolute;
        right: 0;
        top: 3px;
        color: rgb(151, 5, 168);
        font-size: 14px;
        font-weight: bold;
        height: 40px;
        background-color: #fff;
        border: none;
      }
    }
  }
  .agreement {
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #999;
    .check {
      width: 16px;
      height: 16px;
      border: 1px solid #bbbbbb;
      border-radius: 50%;
      margin-right: 5px;
      &.con {
        background: url(../assets/img/ic_xuanzhong_bg.png);
        background-size: 100%;
        border: 1px solid #ffc814;
      }
    }
    p {
      font-size: 12px;
      span {
        color: #ffc814;
      }
    }
  }
  .AccountLogin {
    font-size: 17px;
    height: 37px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .go {
    display: flex;
    justify-content: center;
  }
  .register {
    background-color: #a93ff4;
    color: #fff;
    height: 52px;
    width: 268px;
    border-radius: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
</style>